package com.famid.flashcards;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.famid.flashcards.data.CardStack;

public class ListAdapter extends ArrayAdapter<CardStack>{

	private final List<CardStack> stacks;
	private final Context context;
	
	public ListAdapter(Context context, List<CardStack> stacks) {
		super(context, R.layout.list_item_view, stacks);
		this.stacks = stacks;
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.list_item_view, parent, false);
		TextView title = (TextView) rowView.findViewById(R.id.list_item_title);
		TextView totalCards = (TextView) rowView.findViewById(R.id.list_item_total_cards);
		TextView knownPercent = (TextView) rowView.findViewById(R.id.list_item_known_precent);
		CardStack cs = stacks.get(position);
		title.setText(cs.getTitle());
		totalCards.setText(String.valueOf(cs.getCardSize()));
		knownPercent.setText(cs.getKnownPercent()+" %");
		return rowView;
	}
}
